<?php
use think\migration\Migrator;
use think\migration\db\Column;

class AddUserIdToExamUserAnswer extends Migrator
{
    public function up()
    {
        // use raw SQL to add column, respect table prefix
        $prefix = config('database.prefix') ?: '';
        $tableName = $prefix . 'exam_user_answer';
        $sql = "ALTER TABLE `{$tableName}` ADD COLUMN `user_id` INT NOT NULL DEFAULT 0 COMMENT '考生ID' AFTER `user_paper_id`";
        $this->execute($sql);
    }

    public function down()
    {
        $prefix = config('database.prefix') ?: '';
        $tableName = $prefix . 'exam_user_answer';
        $sql = "ALTER TABLE `{$tableName}` DROP COLUMN `user_id`";
        $this->execute($sql);
    }
}
